@using CleanArchitecture.Blazor.Application.Features.Departments.Commands.AddEdit
@using SixLabors.ImageSharp
@using SixLabors.ImageSharp.Formats
@using SixLabors.ImageSharp.Processing
@inherits MudComponentBase
@inject IStringLocalizer<Departments> L
<MudDialog>
    <DialogContent>
        <MudForm Model="model" @ref="form" Validation="@(modelValidator.ValidateValue)">
            <MudGrid>
                <MudItem xs="12">
                    <MudTextField Label="@L["Department Name"]" @bind-Value="model.Name"
                                  For="@(() => model.Name)"
                                  Required="true"
                                  RequiredError="@L["department name is required!"]"
                                  >
                    </MudTextField>
                </MudItem>
                <MudItem xs="12">
                    <PicklistAutocomplete Picklist="Picklist.ActiveStatus" Label="@L["Status"]"
                                  Required="true"
                                  RequiredError="@L["status is required!"]"
                                  For="@(() => model.Status)"
                                  @bind-Value="model.Status"></PicklistAutocomplete>
                </MudItem>
                
            </MudGrid>
        </MudForm>
    </DialogContent>
    <DialogActions>
        <MudButton OnClick="Cancel">@L["Cancel"]</MudButton>
        <MudButton Color="MudBlazor.Color.Primary" OnClick="Submit">@L["Ok"]</MudButton>
    </DialogActions>
</MudDialog>

@code {
    MudForm form = default!;
    [CascadingParameter]
    MudDialogInstance MudDialog { get; set; } = default!;
    AddEditDepartmentCommandValidator modelValidator = new AddEditDepartmentCommandValidator();
    [EditorRequired] [Parameter] public AddEditDepartmentCommand model { get; set; } = default!;

    async Task Submit()
    {
        await form.Validate();
        if (form.IsValid)
        {
            MudDialog.Close(DialogResult.Ok(true));
        }

    }
    void Cancel() => MudDialog.Cancel();
}
